package com.university.report.user.consumer;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.university.report.common.constant.RabbitMQConst;
import com.university.report.model.entity.ReportInfo;
import com.university.report.model.entity.UserInfo;
import com.university.report.model.exception.UserNotFoundException;
import com.university.report.user.mapper.ReportInfoMapper;
import com.university.report.user.mapper.UserInfoMapper;
import com.university.report.user.service.ReportInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * @ClassName health_report
 * @Author Jinondo
 * @Date 2021/6/18 14:41
 */
@Component
@Slf4j
public class ReportInfoConsumer {
    @Autowired
    ObjectMapper objectMapper;

    @Autowired
    ReportInfoService reportInfoService;

    @RabbitListener(queues = {RabbitMQConst.REPORT_QUEUE})
    public void receiveReport(@Payload byte[] message){
        try {
            ReportInfo reportInfo = objectMapper.readValue(message,ReportInfo.class);
            log.info(">> 健康上报消息成功接受 <<");
            ReportInfoService.ReportStatus status = reportInfoService.report(reportInfo);
            log.info(status.getMessage());
        } catch (Exception e){
            log.info("=== 监听消费健康上报消息 发生异常 ===");
            e.printStackTrace();
        }
    }


}
